#ifndef __MINMAX2DBOX_H__
#define __MINMAX2DBOX_H__
#include "Point2D.h"
#include "Point3D.h"

namespace geom
{
	class MinMax2DBox
	{
		public:
			MinMax2DBox(const Point2D &p);
			MinMax2DBox(const Point2D &p1, const Point2D &p2, const Point2D &p3);
			MinMax2DBox(const Point3D &p);
			MinMax2DBox(const Point3D &p1, const Point3D &p2, const Point3D &p3);

            inline void updateBoxWith(const Point3D &p)
            {
                updateBoxWith(Point2D(p.x,p.z));
            }

            inline void updateBoxWith(const Point2D &p)
			{
				if(p.x < m_min.x) m_min.x = p.x;
				if(p.y < m_min.y) m_min.y = p.y;
				if(p.x > m_max.x) m_max.x = p.x;
				if(p.y > m_max.y) m_max.y = p.y;
			}

			bool containsPoint(const Point2D &p) const;
			bool containsPoint(float x, float y) const;
			const Point2D& min() const {return m_min;}
			const Point2D& max() const {return m_max;}

			inline float width() const{return (m_max.x-m_min.x);}
			inline float height() const{return (m_max.y-m_min.y);}
			float area() const{return width() * height();}

		private:
            inline Point2D point3DTo2D(const Point3D &p){return Point2D(p.x,p.z);}
			Point2D m_min;
			Point2D m_max;
	};
}
#endif
